const { select } = require('../db/mysql');
var moment = require('moment');
//登录
const login = (data) => {
  let sql = `SELECT * from user
    WHERE username='${data.username}';`;
  return select(sql);
}
//用户信息是否存在（通过ip查询）
const userInserted = (data)=>{
  let sql = `SELECT * from user
    WHERE id='${data.openid}';`;
  return select(sql);
}

//注册
const register = (data) => {
  let sql = `INSERT INTO user (name,username,password,age,sex,lastTime,creator) 
    VALUES("${data.name}","${data.username}","${data.password}","${data.age}","${data.sex}","${data.regiserTime}","${data.creator}");
    INSERT INTO createruser (creator,regiserTime,name) VALUES("${data.creator}","${data.regiserTime}","${data.name}")`
  return select(sql);
}

module.exports = {
  login,//登录
  register,//注册
  userInserted,//查询用户微信ip是否存在
}